import 'package:flutter/material.dart';
import 'package:flutter_github_login/localstorage.dart';

import '../../http_utils.dart';
import '../../routes.dart';

var selectColor = Color(0xff333333);
var unSelectColor = Color(0x99333333);

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  Color backgroundColor = Color(0xff000000);
  int currentIndex = 0;

  final List<BottomNavigationBarItem> bottomNavItems = [
    const BottomNavigationBarItem(
      icon: Icon(Icons.home),
      label: "首页",
    ),
    const BottomNavigationBarItem(
      icon: Icon(Icons.message),
      label: "消息",
    ),
    const BottomNavigationBarItem(
      icon: Icon(Icons.person),
      label: "我的",
    ),
  ];
  final pages = [
    const TabMine(),
    const TabMine(),
    const TabMine(),
    const TabMine(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: BottomNavigationBar(
        items: bottomNavItems,
        selectedItemColor: selectColor,
        unselectedItemColor: unSelectColor,
        currentIndex: currentIndex,
        iconSize: 20,
        selectedFontSize: 14,
        type: BottomNavigationBarType.fixed,
        onTap: (index) {
          _changePage(index);
        },
      ),
      body: pages[currentIndex],
    );
  }

  /*切换页面*/
  void _changePage(int index) {
    /*如果点击的导航项不是当前项  切换 */
    if (index != currentIndex) {
      setState(() {
        currentIndex = index;
      });
    }
  }
}

class TabMine extends StatelessWidget {
  const TabMine({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        elevation: 0,
        title: Text(
          '我的',
          style: TextStyle(color: Colors.black),
        ),
        centerTitle: true,
        actions: [
          IconButton(
              onPressed: () {
                Navigator.pushNamed(context, 'setting');
              },
              icon: Icon(
                Icons.settings,
                color: Colors.black,
              ))
        ],
      ),
      body: ListView(
        children: [
          Text(
            LocalStorage.get("user"),
            style: TextStyle(),
          ),
          ElevatedButton(
            onPressed: () {
              Navigator.pushReplacementNamed(context, Routes.login);
              LocalStorage.save("user", "");
            },
            child: Text(
              '退出登录',
              style: TextStyle(),
            ),
          )
        ],
      ),
    );
  }
}
